package com.hgz.ssmdemo.service.impl;

import com.hgz.ssmdemo.common.exceptions.user.UserInfoException;
import com.hgz.ssmdemo.entity.User;
import com.hgz.ssmdemo.mapper.UserMapper;
import com.hgz.ssmdemo.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 小志
 * @date 2025/6/25 - 15:23
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    /**
     * 用户mapper
     */
    private final UserMapper userMapper;

    @Override
    public void saveUser(User user) {
        try {
            userMapper.saveUser(user);
        } catch (Exception e) {
            throw new UserInfoException(1001,"添加用户失败，请稍后重试");
        }
    }

    @Override
    public void delete(Integer userId) {
        try {
            userMapper.deleteUser(userId);
        } catch (Exception e) {
            throw new UserInfoException(1002,"删除用户失败，请稍后重试");
        }
    }

    @Override
    public void updateUser(User user) {
        try {
            userMapper.updateUser(user);
        } catch (Exception e) {
            throw new UserInfoException(1003,"修改用户失败，请稍后重试");
        }
    }

    @Override
    public User getByUserid(Integer userId) {
            throw new UserInfoException(1004,"获取用户信息失败，请稍后重试");
//        try {
//            return userMapper.getUserById(userId);
//        } catch (Exception e) {
//            throw new UserInfoException(1004,"获取用户信息失败，请稍后重试");
//        }
    }

    @Override
    public List<User> listUser() {
        try {
            return userMapper.listUser();
        } catch (Exception e) {
            throw new UserInfoException(1005,"获取所有用户信息失败，请稍后重试");
        }
    }
}
